<?php
/**
 * Contact Interviews
 */
use Fox\Behaviors;
use Fox\Dao\SqlFragment;
use Hive\Contact\Interview\Type;
use Hive\Ressource;
use Fox\Generator;
use Fox\Html\Button;
use Fox\Html\Header\Content;

/* @var $contact Hive\Ressource */
$contact = Xview::instance()->component('ressource', 'object');
$data = $contact->getData();
$rid = $contact->getId();
$interviews = $contact->interviews();
// Customizing
$customizing = Hive\Ressource\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'ressource','act'=>'interviews'));
$interviewsTextsLabel = $customizing->interviewsTextsLabel();

$html= null;
$header = new Content('jobs',Msg(Hive::BUNDLE,Hive::TITLE_INTERVIEWS));
$header->add(new Button('add','?',Msg(Hive::BUNDLE,Hive::BUT_ADD_INTERVIEW)))
		->color(Button::COLOR_WARNING)
		->behaviors(Behaviors::action(
				Generator::url('ressource','interviews','add',array('rid' => $contact->getId())),
				true,null,null,true));
// Load Type of interview
foreach(Type::loadActives() as $item) {
	$types[$item->type] = $item->label();
}
$behaviorSource = new Behaviors(Behaviors::source(Generator::url('ressource','interviews',null,array('rid' => $rid))));
// Display Interviews
foreach($interviews as $interview) { 
	$iid = $interview->iid;
	$status = $interview->interview_status;
	$type = $interview->interview_type;
	// Title 
	if(empty($type)) {
		$title = Msg(Hive::BUNDLE,Hive::MSG_INTERVIEW);
	} else {
		$title =  $types[$interview->interview_type];
	}
	
	// Sub Title and Links
	$dateString = Fox\Utilities\Dates::dateTimeToFullString($interview->plan_date);
	if($status == 1 || empty($status)) {
		$subTitle = Msg(Hive::BUNDLE,Hive::MSG_INTERIEW_PLAN_SUBTITLE,User::fullName($interview->interviewer),$dateString);
	} else {
		$subTitle = Msg(Hive::BUNDLE,Hive::MSG_INTERIEW_SUBTITLE,User::fullName($interview->interviewer),$dateString);
	}
	
	// Update
	$behaviorUpdate = new Behaviors(Behaviors::action(Generator::url('ressource','interviews','update',
								array('rid' => $rid,'iid' => $interview->iid)),true,null,null,true));
	$behaviorUpdate->add(Behaviors::value('slink'));
	// Delete
	$behaviorDelete = new Behaviors(Behaviors::action(Generator::url('ressource','interviews','delete',
								array('inlineid' => $interview->getInLineId())),true,null,null,true));
	$behaviorDelete->add(Behaviors::value('slink del'));
	$texts = null;
	$text1 = $interview->text1;
	if(!empty($text1)) {
		$texts .= '<h4>'.$interviewsTextsLabel[1].'</h4><p>'.Fox\Utilities\Text::toHtml(stripslashes($interview->text1)).'</p>';
	}
	$text2 = $interview->text2;
	if(!empty($text2)) {
		$texts .= '<h4>'.$interviewsTextsLabel[2].'</h4><p>'.Fox\Utilities\Text::toHtml(stripslashes($interview->text2)).'</p>';
	}
	$text3 = $interview->text3;
	if(!empty($text3))
	{
		$texts .= '<h4>'.$interviewsTextsLabel[3].'</h4><p>'.Fox\Utilities\Text::toHtml(stripslashes($interview->text3)).'</p>';
	}
	$html .= '<li class="mbs pbm noteEntry uiListItem uiListLight uiListVerticalItemBorder">
				<div class="mvs fsl fwb fcb">
					<span class="uiListItemTitle">'.$title.'</span>
				</div>
				<div class="pbm fsm fwn fcg">
					'.$subTitle.' &#8226; 
					<span class="UIActionLinks UIActionLinks_bottom">
						<a href="#" id="upd_'.$iid.'" class="'.$behaviorUpdate->serialize(array(),'').'">'.Msg(Hive::BUNDLE,Hive::UPDATE).'</a>
						 &#8226; <a href="#" id="del_'.$iid.'" class="'.$behaviorDelete->serialize(array(),'').'">'.Msg(Hive::BUNDLE,Hive::DELETE).'</a>
					</span>
				</div>
				<div class="clearfix interview-text">
					<div>
						'.$texts.'
					</div>
				</div>
			</li>';
} 

if(count($interviews) > 0) {
	$html = '<ul>'.$html.'</ul>';
} else {
	$html = '<p class="prettyprint">'.Msg(Hive::BUNDLE,Hive::NO_INTERVIEWS_PLAN).'</p>';
}
?>
<div>
	<div class="page-header clearfix">
		<?php echo $header->render();?>
	</div>
	<div class="contentArea source {'uri':'?mod=ressource&act=interviews&rid=<?php echo $rid;?>'}" >
		<div class="mbs">
			<?php echo $html;?>
		</div>
	</div>
</div>